import { fetchAccountRemain } from "@/api";
import { sessionStorage } from "@/utils";

export default {
  namespaced: true,
  state: {
    remain: 0
  },
  mutations: {
    SET_REMAIN(state, value) {
      state.remain = value;
    }
  },
  actions: {
    UPDATE_REMAIN({
      commit
    }) {
      let user = sessionStorage.get("USER");
      fetchAccountRemain({
        query: {
          userId: user.userId
        }
      }).then(res => {
        commit("SET_REMAIN", res.data.remain)
      });
    }
  }
}